//
//  HomeOnlineTrainListTableViewCell.m
//  ZJControlsClass
//
//  Created by wandoufo on 2024/12/8.
//

#import "ZJHomeOnlineCoursewaresTableViewCell.h"
#import "HomeOnlineTrainModel.h"
#import "HomeOnlineTrainDetailViewController.h"
#import "ZJCreateOnlineCourseWorking.h"
#import "Masonry.h"


@interface ZJHomeOnlineCoursewaresTableViewCell ()
@property (nonatomic, strong) UILabel *tagLabel;
@property (nonatomic, strong) UILabel *statusLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UILabel *durationLabel;
@property (nonatomic, strong) UIView *contentBgView;
@end



@implementation ZJHomeOnlineCoursewaresTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor clearColor];
        [self setupUI];
        
    }
    return self;
}

- (void)setupUI {
    // 外层背景视图
    UIView *bgView = [[UIView alloc] init];
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView).inset(12);
        make.top.equalTo(self.contentView).offset(16);
        make.bottom.equalTo(self.contentView);
    }];
    
    // 内容背景视图（带边框）
    UIView *contentBgView = [[UIView alloc] init];
    contentBgView.backgroundColor = [UIColor whiteColor];
    contentBgView.layer.cornerRadius = 8;
    contentBgView.layer.borderWidth = 0.5;
    contentBgView.layer.borderColor = [UIColor mainColor].CGColor;
    [bgView addSubview:contentBgView];
    [contentBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(bgView);
    }];
    
    // 标签（视频/图文）
    UILabel *tagLabel = [[UILabel alloc] init];
    tagLabel.backgroundColor = [UIColor mainColor];
    tagLabel.textColor = [UIColor whiteColor];
    tagLabel.font = [UIFont systemFontOfSize:12];
    tagLabel.textAlignment = NSTextAlignmentCenter;
    [contentBgView addSubview:tagLabel];
    [tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(contentBgView);
        make.top.equalTo(contentBgView).offset(8);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(20);
    }];
    
    // 内容标题
    UILabel *contentLabel = [[UILabel alloc] init];
    contentLabel.font = [UIFont boldSystemFontOfSize:14];
    contentLabel.textColor = [UIColor mainColor];
    contentLabel.numberOfLines = 0;
    [contentBgView addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(contentBgView).inset(10);
        make.top.equalTo(tagLabel.mas_bottom).offset(8);
    }];
    
    
    // 内容标题
    self.statusLabel  = [[UILabel alloc] init];
    self.statusLabel.font = [UIFont systemFontOfSize:14];
    self.statusLabel.textColor = [UIColor ntes_colorWithHexString:@"181818"];
    self.statusLabel.numberOfLines = 0;
    [contentBgView addSubview:self.statusLabel];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(contentBgView).inset(10);
        make.centerY.equalTo(tagLabel);
//        make.top.equalTo(tagLabel.mas_bottom).offset(8);
    }];
    
    // 时长标签
    UILabel *durationLabel = [[UILabel alloc] init];
    durationLabel.font = [UIFont systemFontOfSize:12];
    durationLabel.textColor = [UIColor colorWithHexString:@"666666"];
    durationLabel.numberOfLines = 0;
    [contentBgView addSubview:durationLabel];
    [durationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(contentBgView).inset(10);
        make.top.equalTo(contentLabel.mas_bottom).offset(8);
        make.bottom.equalTo(contentBgView).offset(-8);
    }];
    
    // 保存为属性以便后续设置数据
    self.tagLabel = tagLabel;
    self.contentLabel = contentLabel;
    self.durationLabel = durationLabel;
    self.contentBgView = contentBgView;
}

- (void)setModel:(HomeOnlineCoursewareModel *)model {
    _model = model;
    
    // 根据状态设置样式
    
    
    // 设置标签文字和样式
    self.tagLabel.text = [model.fileType isEqualToString: @"pdf"] ? @"图文" : @"视频";
    self.tagLabel.backgroundColor = model.isSelected ? [UIColor mainColor] : [UIColor colorWithHexString:@"999999"];
    
    // 设置背景和边框
    self.contentBgView.backgroundColor = model.isSelected ? [UIColor whiteColor] : [UIColor colorWithHexString:@"F4F4F4"];
    self.contentBgView.layer.borderColor = model.isSelected ? [UIColor mainColor].CGColor : [UIColor colorWithHexString:@"F4F4F4"].CGColor;
    
    // 设置文字颜色
    self.contentLabel.textColor = model.isSelected ? [UIColor mainColor] : [UIColor colorWithHexString:@"333333"];
    self.statusLabel.textColor = model.isSelected ? [UIColor colorWithHexString:@"181818"] : [UIColor colorWithHexString:@"666666"];
    
    // 设置内容
    self.contentLabel.text = model.name;
    self.durationLabel.text = model.remarks;
    self.statusLabel.text = model.statusName;
}






@end

